package com.tangula.voicenote

import android.util.Log
import com.tangula.android.base.TglBasicApplication
import com.tangula.android.orm.BaseDataBaseHelper
import com.tangula.android.orm.ContextSupplier
import com.tangula.android.utils.ApplicationUtils
import com.tangula.voicenote.db.DbCreator
import com.tangula.voicenote.db.NoteDbHelper
import com.tangula.voicenote.entity.NoticeEntity
import com.tangula.voicenote.service.AddOverlayService

class VoiceNoteApplication:TglBasicApplication() {

    companion object {

        const val COLOR_COUNT = 10

        lateinit var NOTE_TOOLS: Array<String>
    }

    override fun onCreate() {
        super.onCreate()
        Log.v("console", "application created")
        NOTE_TOOLS = ApplicationUtils.APP.resources.getStringArray(R.array.tools)

        BaseDataBaseHelper.CONTEXT_FAC = ContextSupplier { this }
        BaseDataBaseHelper.setDbCreator(DbCreator())


        val list = NoteDbHelper().listAllNotes()

        if(list.isEmpty()){
            Log.v("console", "notes is empty")
            AddOverlayService.addOverlayService()
        }else {
            Log.v("console", "notes size is ${list.size}")
            for (note in list) {
                Log.v("console", "note: ${note.id} , ${(note as NoticeEntity).message}")
                AddOverlayService.addOverlayServiceById(note.id)
            }
        }

    }
}